﻿using System;
using System.Collections.Generic;
using Ext.Net;
using BLL;
using Model;
using System.Xml;
using System.Xml.Xsl;

namespace Web.View.h30_ypzdMenu
{
    public partial class Default : UIPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        //绑定Grid
        protected void h30_ypzd_DataBind(object sender, StoreRefreshDataEventArgs e)
        {
            h30_ypzdMgr mgr = new h30_ypzdMgr();
            e.Total = int.Parse(mgr.GetRecordCount_h30_ypzd(e.Parameters[h30_ypzd_Filter.ParamPrefix]));
            IList<h30_ypzd> list = mgr.FindAllByPage_h30_ypzd(e.Start.ToString(), e.Limit.ToString(), e.Parameters[h30_ypzd_Filter.ParamPrefix]);
            h30_ypzd_MainStore.DataSource = list;
            h30_ypzd_MainStore.DataBind();
        }
        //删除数据
        protected void BtnDel_Click(object sender, DirectEventArgs e)
        {
            h30_ypzdMgr mgr = new h30_ypzdMgr();
            RowSelectionModel sm = h30_ypzd_Grid.SelectionModel.Primary as RowSelectionModel;
            foreach (SelectedRow row in sm.SelectedRows)
            {
                h30_ypzd _h30_ypzd = new h30_ypzd();
                _h30_ypzd.ypid = row.RecordID;//int.Parse(row.RecordID);
                if (mgr.Del_h30_ypzd(_h30_ypzd))
                {
                    log.Debug("h30_ypzd中执行了删除，并成功");
                    X.Msg.Notify("成功", "<font color='green'>已经成功删除选中的记录</font>").Show();
                }
                else
                    X.Msg.Notify("失败", "<font color='green'>删除记录失败，请您重试！</font>").Show();
            }
            h30_ypzd_Grid.Reload();
        }
        protected void BtnSave_Click(object sender, DirectEventArgs e)
        {
            h30_ypzdMgr mgr = new h30_ypzdMgr();
            h30_ypzd _h30_ypzd = new h30_ypzd();
            if (Hid.Text.Length > 0)
                _h30_ypzd = mgr.FindById_h30_ypzd(int.Parse(Hid.Text));
            
			_h30_ypzd.zwmc = Txtzwmc.Text.Trim();
			_h30_ypzd.bzbm = Txtbzbm.Text.Trim();
			_h30_ypzd.ypflid = Txtypflid.Text.Trim();
			_h30_ypzd.ypflbm = Txtypflbm.Text.Trim();
			_h30_ypzd.ypgg = Txtypgg.Text.Trim();
			_h30_ypzd.yphl = Txtyphl.Text.Trim();
			_h30_ypzd.hlxs = Txthlxs.Text.Trim();
			_h30_ypzd.hldw = Txthldw.Text.Trim();
			_h30_ypzd.jxflid = Txtjxflid.Text.Trim();
			_h30_ypzd.spmc = Txtspmc.Text.Trim();
			_h30_ypzd.ywmc = Txtywmc.Text.Trim();
			_h30_ypzd.ldmc = Txtldmc.Text.Trim();
			_h30_ypzd.szbm = Txtszbm.Text.Trim();
			_h30_ypzd.pybm = Txtpybm.Text.Trim();
			_h30_ypzd.wbbm = Txtwbbm.Text.Trim();
			_h30_ypzd.qtbm = Txtqtbm.Text.Trim();
			_h30_ypzd.syffid = Txtsyffid.Text.Trim();
			_h30_ypzd.syplid = Txtsyplid.Text.Trim();
			_h30_ypzd.ycjl = Txtycjl.Text.Trim();
			_h30_ypzd.yrjl = Txtyrjl.Text.Trim();
			_h30_ypzd.yjjl = Txtyjjl.Text.Trim();
			_h30_ypzd.ejjl = Txtejjl.Text.Trim();
			_h30_ypzd.sjjl = Txtsjjl.Text.Trim();
			_h30_ypzd.yexs = Txtyexs.Text.Trim();
			_h30_ypzd.esxs = Txtesxs.Text.Trim();
			_h30_ypzd.ysxs = Txtysxs.Text.Trim();
			_h30_ypzd.cfqj = Txtcfqj.Text.Trim();
			_h30_ypzd.zzbz = Txtzzbz.Text.Trim();
			_h30_ypzd.pwjj = Txtpwjj.Text.Trim();
			_h30_ypzd.qtjj = Txtqtjj.Text.Trim();
			_h30_ypzd.dybz = Txtdybz.Text.Trim();
			_h30_ypzd.mzbz = Txtmzbz.Text.Trim();
			_h30_ypzd.gzbz = Txtgzbz.Text.Trim();
			_h30_ypzd.jsl1 = Txtjsl1.Text.Trim();
			_h30_ypzd.jsl2 = Txtjsl2.Text.Trim();
			_h30_ypzd.jkbz = Txtjkbz.Text.Trim();
			_h30_ypzd.ybfl = Txtybfl.Text.Trim();
			_h30_ypzd.abcfl = Txtabcfl.Text.Trim();
			_h30_ypzd.fylbid = Txtfylbid.Text.Trim();
			_h30_ypzd.zflx = Txtzflx.Text.Trim();
			_h30_ypzd.zyyt = Txtzyyt.Text.Trim();
			_h30_ypzd.yfyl = Txtyfyl.Text.Trim();
			_h30_ypzd.zysx = Txtzysx.Text.Trim();
			_h30_ypzd.zcff = Txtzcff.Text.Trim();
			_h30_ypzd.bzxx = Txtbzxx.Text.Trim();
			_h30_ypzd.bfxs = Txtbfxs.Text.Trim();
			_h30_ypzd.tyid = Txttyid.Text.Trim();
			_h30_ypzd.id = int.Parse(TxtNumid.Text.Trim());

            bool isok = false;
            if (Hid.Text.Length > 0)
                isok = mgr.Update_h30_ypzd(_h30_ypzd);
            else
                isok = mgr.Add_h30_ypzd(_h30_ypzd);
            if (isok)
            {
                h30_ypzd_Win.Hide();
                X.Msg.Notify("成功", "<font color='green'>恭喜您，操作成功！</font>").Show();
                log.Debug("h30_ypzd中执行了保存（插入或修改），并成功");
                h30_ypzd_Grid.Reload();
            }
            else
                X.Msg.Notify("失败", "<font color='red'>操作失败，请您重试！</font>").Show();
        }
        //数据保存为Excel
        protected void BtnSaveToExcel(object sender, EventArgs e)
        {
            string json = ExcelGridData.Value.ToString();
            StoreSubmitDataEventArgs eSubmit = new StoreSubmitDataEventArgs(json, null);
            XmlNode xml = eSubmit.Xml;
            this.Response.Clear();
            this.Response.ContentType = "application/vnd.ms-excel";
            this.Response.AddHeader("Content-Disposition", "attachment; filename=QiDian10Excel.xls");
            XslCompiledTransform xtExcel = new XslCompiledTransform();
            xtExcel.Load(Server.MapPath("/View/ExcelTemp/Excel.xsl"));
            xtExcel.Transform(xml, null, this.Response.OutputStream);
            this.Response.End();

        }
    }
}